package com.ok.common.utils

sealed class ErrorCode(val code: Int, val msg: String) {
    object SUCCESS : ErrorCode(0, "成功")
    object COMMON_FAILED : ErrorCode(-1, "失败")
}

data class Result<T>(
    val success: Boolean = true,
    val msg: String = ErrorCode.SUCCESS.msg,
    val data: T? = null
) {
    companion object {

        @JvmOverloads // 添加注解支持Java的可选参数调用
        fun <T> success(
            msg: String = ErrorCode.SUCCESS.msg,
            data: T? = null,
        ): Result<T> =
            Result(success = true, msg = msg, data = data)

        @JvmOverloads
        fun <T> failed(
            msg: String = ErrorCode.COMMON_FAILED.msg,
            data: T? = null,
        ): Result<T> =
            Result(success = false, msg = msg, data = data)

    }
}